package com.zin.viewpagerfragment.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.zin.viewpagerfragment.R;

import java.util.ArrayList;
import java.util.List;

import entity.ListBean;
import entity.NewsData;
import htpp.Httpconnection;
import util.Utils;


public class LaunchUIFragment extends Fragment {

List<ListBean> list=new ArrayList<ListBean>();
TextView textView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_selection_launch,
				container, false);
		textView= (TextView) rootView.findViewById(R.id.textlauch);
		//String tojson= Httpconnection.getJsonData("tech");
	/*	Httpconnection tojson=new Httpconnection();
		String strotojson=tojson.getJsonData("tech");
         System.out.println(strotojson);*/
	/*	NewsData newdata = JSON.parseObject(tojson, NewsData.class);
		list=newdata.getList();
		textView.setText(list.get(0).getDocurl());*/
		getJsonData("tech");
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	public   void getJsonData(String type) {


		new HttpUtils().send(HttpRequest.HttpMethod.GET,
				"http://wangyi.butterfly.mopaasapp.com/news/api?type="+type+"&page=1&limit=12",
				new RequestCallBack<String>() {
					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						String json = responseInfo.result;
						System.out.println("}}}}}"+json);
						//保存json文件
						NewsData newdata = JSON.parseObject(json, NewsData.class);
						list=newdata.getList();
						textView.setText(list.get(0).getDocurl());

						//   timer.schedule(timetask, 2000); //定时器

					}

					@Override
					public void onFailure(HttpException e, String s) {

						Utils.show("当前网络不可访问");

					}
				});

	}





}
